package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.model.request.PathConfigRequest;
import com.ytjj.qmyx.admin.service.PathConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/pathConfig")
public class PathConfigController {

    @Autowired
    private PathConfigService pathConfigService;

    @RequiresPermissions("pathConfig:list")
    @PostMapping("/list")
    @OperLog(operModule = "路径配置模块", operDesc = "路径配置列表", operType = SysLogConstants.OPERATION_SELECT)
    public CommonResult selectList(@RequestBody PathConfigRequest pathConfigRequest) {
        return CommonResult.success(pathConfigService.selectList(pathConfigRequest));
    }

    @RequiresPermissions("pathConfig:insertPathConfig")
    @PostMapping("/insertPathConfig")
    @OperLog(operModule = "路径配置模块", operDesc = "增加路径配置", operType = SysLogConstants.OPERATION_ADD)
    public CommonResult insertPathConfig(@RequestBody PathConfigRequest pathConfigRequest) {
        int count = pathConfigService.insertPathConfig(pathConfigRequest);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @RequiresPermissions("pathConfig:updatePathConfig")
    @RequestMapping("/updatePathConfig")
    @OperLog(operModule = "路径配置模块", operDesc = "修改路径配置", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult updatePathConfig(@RequestBody PathConfigRequest pathConfigRequest) {
        int count = pathConfigService.updatePathConfig(pathConfigRequest);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

}
